/*
This file is part of maven-rabbit-plugin.

maven-rabbit-plugin is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

maven-rabbit-plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with maven-rabbit-plugin.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.opensource.maven.rabbit;

import java.net.URL;
import org.apache.maven.plugin.AbstractMojo;
import org.opensource.nabaztag.Rabbit;

/**
 * Abstract class allowing to manipulate an initialized Nabaztag.
 */
public abstract class AbstractRabbitMojo extends AbstractMojo {

    /**
     * Serial number of the Nabaztag.
     *
     * @parameter expression="${rabbit.sn}
     * @required
     */
    private String serialNumber;

    /**
     * Token of the Nabaztag.
     *
     * @parameter expression="${rabbit.token}
     * @required
     */
    private String token;

    /**
     * API URL used, if not violet default platform.
     *
     * @parameter expression="${rabbit.APIURL}
     */
    private URL nabaztagAPIURL;

    /**
     * Stream API URL used, if not violet default platform.
     *
     * @parameter expression="${rabbit.streamAPIURL}
     */
    private URL nabaztagStreamAPIURL;

    /**
     * Returns a Rabbit instyance initialized.
     *
     * @return rabbit instance
     */
    protected final Rabbit getRabbit() {
        final Rabbit rabbit = new Rabbit(this.serialNumber, this.token);
        if (this.nabaztagAPIURL != null) {
            rabbit.setNabaztagAPI(this.nabaztagAPIURL);
        }
        if (this.nabaztagStreamAPIURL != null) {
            rabbit.setNabaztagStreamAPI(this.nabaztagStreamAPIURL);
        }
        return rabbit;
    }

}
